package com.hup.minicontroller.server.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.hup.minicontroller.server.ServerApplication;
import com.hup.minicontroller.server.service.MainService;

import lombok.Getter;


/**
 * Created by caigh on 2017/7/18.
 */

public class BootReceiver extends BroadcastReceiver {
    private static final String TAG = BootReceiver.class.getSimpleName();

    /**
     * 收到开机广播的时间;
     * 这是在Application.onCreate完全执行完后才会收到的!
     */
    @Getter
    private static Long bootTime;

    @Override
    public void onReceive(Context context, Intent i) {
        String action = i.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
            Log.i(TAG, "设备开机");
            bootTime = System.currentTimeMillis();
            //事件在Application.onCreate执行完后才会收到!
        } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
            Log.i(TAG, "设备关机");
            ServerApplication.getBean(MainService.class).onDeviceShuttingDown();
        }

    }


}
